package com.aneliya.command.chatWindow;

import com.aneliya.framework.mvc.Facade;
import com.aneliya.framework.mvc.controller.ICommand;
import com.aneliya.framework.mvc.controller.MVCEvent;
import com.aneliya.mediator.ChatWindowMediator;
import com.aneliya.mediator.LoginDialogMediator;
import com.aneliya.proxy.MessagesProxy;

public class CloseChatWindowCommand implements ICommand {

	public void execute(MVCEvent event) {
		try {
			MessagesProxy messagesProxy = 
				(MessagesProxy) Facade.getInstance().retrieveProxy("MessagesProxy");
			messagesProxy.saveHistory();
			
			ChatWindowMediator chatWindowMediator = 
				(ChatWindowMediator) Facade.getInstance().retrieveMediator("ChatWindowMediator");
			LoginDialogMediator loginDialogMediator = 				
				(LoginDialogMediator) Facade.getInstance().retrieveMediator("LoginDialogMediator");
			
			chatWindowMediator.getChatWindow().dispose();
			loginDialogMediator.getLoginDialog().dispose();
			System.exit(0);
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}

}
